import React from 'React'
import Navbar from '../navbar'
import  AddressCard from '../addressCard'
import Router,{Link} from'react-router'
import actions from '../actions'
import Reflux from 'reflux'
import ReactMixin from 'react-mixin'
import store from '../store'
import '../../../../less/address.less'

export default class ReceiptA extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            addressList:[],
            changedAddressItem: {}
        }
    }

    selectIndex(index){
        actions.setDefault(index)
    }
    editInfo(index){
        // let info={
        //     name : this.state.addressList[index].name,
        //     phone : this.state.addressList[index].phone,
        //     address : this.state.addressList[index].address,
        //     place : this.state.addressList[index].place,
        //     isDef : this.state.addressList[index].isDef,
        // };
        actions.editAddress(index)
    }
    componentDidMount(){
        actions.getAddressList();
    }
    removeInfo(index){
        actions.removeAddress(index)
    }
    render() {
        let list = [];
        this.state.addressList.map((item, index) => {
            list.push(
                <AddressCard
                    name={item.shoppingMan}
                    phone={item.shoppingManPhone}
                    address={item.locationId}
                    place={item.address}
                    isDef={item.default}
                    index={index}
                    key={index}
                    removeInfo={this.removeInfo.bind(this,index)}
                    editInfo={this.editInfo.bind(this,index)}
                    selectIndex={this.selectIndex.bind(this,index)}
                />
            )
        });
        return (
            <div>
                <Navbar title="收货地址"/>
                {
                    list.length > 0 ?<div className="address-add-box">
                        {list}
                    </div>  :
                        <div className="address-no">
                            <i className="iconfont icon-weizhi-copy"></i>
                            <p className="address-no-shadow"></p>
                            <p className="address-no-p1">没有收货地址</p>
                            <p className="address-no-p2">去添加地址吧，购物会更方便哦！</p>
                            <Link to="/address/add">
                                <div className="address-btn">
                                    <i className="iconfont icon-add"></i>添加地址
                                </div>
                            </Link>
                        </div>
                }

            </div>
        )
    }
}

ReactMixin.onClass(ReceiptA, Reflux.connect(store));
